<template>
  <div class="box_item">
    <div class="box_top">
      <div class="item">
        <div class="item_left" v-for="(item, index) in tabData" :key="index" @click="formData(item)">
          <div class="item_left_text">
            {{ item.name }}
          </div>
          <div class="item_left_value">
            {{ item.value }}
          </div>
        </div>
      </div>
      <div class="item">
        <HorizontalBarChart
          :departments="departments"
          :taskCounts="taskCounts"
          v-if="departments.length > 0"
        />
      </div>
      <div class="item">
        <QualityTaskTable />
      </div>
    </div>
    <Dialog :fathUrl="fathUrl" :arrList="arrList" :visible="bslwsVisible"
      dataChange="4"
      @close="bslwsVisible = false" :title="name">
    </Dialog>
  </div>
</template>
<script setup>
import { onMounted, ref } from "vue";
import QualityTaskTable from "../../../tables/QualityTaskTable.vue";
import QualityFormTable from "../../../tables/QualityFormTable.vue";
import Dialog from "../Dialog.vue";
import HorizontalBarChart from "../../../charts/HorizontalBarChart.vue";
import {
  GETcountDataQualityMetricsDistinct,
  GETcountDataQualityMetrics,
  GETcountDataQualityMetricsDistinctTableName,
  GETcountDataQualityMetricsDistinctColumnName,
  GETlistDwSuppObject1,
  GETcountDataQualityMetricsDistinctMx,
} from "@/api/index";
const departments = ref([]);
const taskCounts = ref([]);
const bslwsVisible = ref(false);
const name = ref('')
const fathUrl = ref('')
const arrList = ref([])
const formData = (val) => {
  if (val.value == '一致性校验记录数') {
    bslwsVisible.value = true
    fathUrl.value = '/zjjscApi/api/dataQuality/countDataQualityMetricsMx'
    arrList.value = [
    {
      prop: "department",
      label: "业务处室",
      width: "80",
    },
    {
      prop: "sourceSystem",
      label: "系统名",
      width: "80",
    },
    {
      prop: "dbName",
      label: "数据库名",
      width: "80",
    },{
      prop: "tableName",
      label: "表名",
      width: "80",
    },
    {
      prop: "columnName",
      label: "字段名",
      width: "80",
    },
    {
      prop: "currentDistinctCount",
      label: "该字段的除重记录数",
      width: "80",
    },{
      prop: "sourceSystem",
      label: "源头系统名",
      width: "80",
    },
    {
      prop: "sourceDb",
      label: "源头数据库名",
      width: "80",
    },
    {
      prop: "sourceColumn",
      label: "源头字段名",
      width: "80",
    }, {
      prop: "sourceDistinctCount",
      label: "源头字段除重记录数",
      width: "80",
    },]
  } else {
    bslwsVisible.value = false
  }
  
  name.value = val.value
  }
//数据质量规则数排名
const awGETlistDwSuppObject1 = async () => {
  await GETlistDwSuppObject1().then((res) => {
    let arr1 = [];
    let arr2 = [];
    if (res.status == 200) {
      res.data.forEach((v) => {
        arr1.push(v.name);
        arr2.push(v.value);
      });
    }
    departments.value = arr1;
    taskCounts.value = arr2;
  }).catch((err)=>{
    departments.value = ["处室一", "处室二", "处室三", "处室四", "处室五", "处室六"]
    taskCounts.value = [6000, 5000, 4000, 3000, 2000, 1000]
  });
};
//一致性校验字段数量
const awGETcountDataQualityMetricsDistinct = async () => {
  await GETcountDataQualityMetricsDistinct().then((res) => {
    if (res.status == 200) {
      tabData.value.push({ name: res.data.count, value: "一致性校验字段数量" });
      awGETcountDataQualityMetrics();
    }
  }).catch((err)=>{
    tabData.value.push({ name: 0, value: "一致性校验字段数量" });
  });
};
//一致性校验字段数量明细
const awGETcountDataQualityMetricsDistinctMx = async () => {
  await GETcountDataQualityMetricsDistinctMx().then((res) => {
    console.log(res, "余旺");
  });
};
//一致性校验记录数
const awGETcountDataQualityMetrics = async () => {
  await GETcountDataQualityMetrics().then((res) => {
    if (res.status == 200) {
      tabData.value.push({ name: res.data.count, value: "一致性校验记录数" });
      awGETGETcountDataQualityMetricsDistinctTableName()
    }
  }).catch((err)=>{
    tabData.value.push({ name: 0, value: "一致性校验记录数" });
  });
};

//数据不一致表数量
const awGETGETcountDataQualityMetricsDistinctTableName = async () => {
  await GETcountDataQualityMetricsDistinctTableName().then((res) => {
    if (res.status == 200) {
      tabData.value.push({ name: res.data.count, value: "数据不一致表数量" });
      awGETcountDataQualityMetricsDistinctColumnName()
    }
  }).catch((err)=>{
    tabData.value.push({ name: 0, value: "数据不一致表数量" });
  });
};

//数据不一致字段数量
const awGETcountDataQualityMetricsDistinctColumnName = async () => {
  await GETcountDataQualityMetricsDistinctColumnName().then((res) => {
    if (res.status == 200) {
      tabData.value.push({ name: res.data.count, value: "数据不一致字段数量" });
    }
  }).catch((err)=>{
    tabData.value.push({ name: 0, value: "数据不一致字段数量" });
  });
};
onMounted(() => {
  awGETcountDataQualityMetricsDistinct();
  // awGETcountDataQualityMetrics();
  // awGETGETcountDataQualityMetricsDistinctTableName();
  // awGETcountDataQualityMetricsDistinctColumnName();

  awGETlistDwSuppObject1();
});

const tabData = ref([]);
onMounted(() => {});
</script>

<style scoped>
.box_item {
  height: 321px;
  background-image: url("../../img/sjzl.png");
}

.box_top {
  display: flex;
  width: 100%;
  height: 271px;
  padding-top: 50px;
  justify-content: space-between;
}

.item {
  width: 336px;
  height: 267px;
  margin-left: 5px;
}

.item:first-child {
  width: 336px;
  box-sizing: border-box;
  background-image: url("../../img/sjyzx.png");
  background-repeat: no-repeat;
  background-position: center center;
  padding: 40px;
  display: flex;
  flex-wrap: wrap;
}

.item:nth-child(2) {
  box-sizing: border-box;
  padding-top: 40px;
  padding-left: 10px;
  width: 336px;
  height: 267px;
  background-image: url("../../img/gebmzljc.png");
  background-repeat: no-repeat;
  background-position: center center;
}

.item:last-child {
  box-sizing: border-box;
  padding-top: 40px;
  /* padding-left: 10px; */
  width: 336px;
  height: 267px;
  background-image: url("../../img/sjhel.png");
  background-repeat: no-repeat;
  background-position: center center;
}

.item_left {
  width: 50%;
  height: 100px;
  background-image: url("../../img/ditu.png");
  background-repeat: no-repeat;
  background-position: center center;
}

.item_left_text {
  width: 200px;
  padding: 30px 30px 0px 44px;
  font-size: 18px;
  font-weight: 700;
}

.item_left_value {
  padding: 40px;
  padding: 40px 0px 0px 0px;
  width: 145px;
  font-size: 14px;
  font-weight: 500;
}
</style>
